from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys

class LeftWidget(QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.btn0 = QPushButton("成绩汇总",self)
        self.init_ui()
        self.set_widget_style()
    def init_ui(self):
        pal = QPalette(self.palette())
        pal.setColor(QPalette.Background,QColor(255,255,255))
        self.setAutoFillBackground(True)
        self.setPalette(pal)
        self.btn0.move(15,40)
        self.btn0.clicked.connect(self.home)
    def set_widget_style(self):
        self.btn0.setStyleSheet("color:rgb(73,166,234);border:none;")
        font = QFont("PingFang SC Regular",20)
        font.setPixelSize(20)
        self.btn0.setFont(font)
        self.setFixedSize(134,370)
    def home(self):
        self.right.close()
        self.right = RightWidget()
        self.right_layout.addWidget(self.right)
    def get_widget_pointer(self,widget,layout):
        self.right = widget
        self.right_layout = layout
class TopWidget(QWidget):
    def __init__(self) -> None:
        super().__init__()
        pal = QPalette(self.palette())
        pal.setColor(QPalette.Background,QColor(255,255,255))
        self.setAutoFillBackground(True)
        self.setPalette(pal)
        #设置logo
        self.logo = QLabel(self)
        self.pix = QPixmap("static/cqu.jpg")
        self.pix = self.pix.scaled(39, 39, Qt.KeepAspectRatio)
        self.logo.setPixmap(QPixmap(self.pix))
        self.logo.move(5,0)
        #设置标题
        self.tittle = QLabel(self)
        self.tittle.setText("成绩汇总")
        font = QFont('PingFang SC Regular',20)
        font.setPixelSize(20)
        self.tittle.setFont(font)
        self.tittle.move(55,0)

        self.side = QLabel(self)
        self.pic = QPixmap("static/people.jpg")
        self.pic = self.pic.scaled(42, 33, Qt.KeepAspectRatio)
        self.side.setPixmap(QPixmap(self.pic))
        self.side.move(660,0)
        self.setFixedSize(732,57)
    

class Test(QWidget):
    def __init__(self):
        super().__init__()
        self.setGeometry(350,250,780,460)
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)
        self.main_wid = QWidget()
        self.main_lay = QHBoxLayout()
        self.main_wid.setLayout(self.main_lay)
        self.left = LeftWidget()
        self.main_lay.addWidget(self.left)
        self.middle = RightWidget()
        self.main_lay.addWidget(self.middle)
        self.top = TopWidget()
        self.layout.addWidget(self.top)
        self.layout.addWidget(self.main_wid)
        self.left.get_widget_pointer(self.middle,self.main_lay)
class RightWidget(QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.resize(600,400)
        self.outside = QVBoxLayout()

        self.firstline = QHBoxLayout()
        self.secondline = QHBoxLayout()
        self.thirdline = QHBoxLayout()

        self.line1 = QLineEdit(self)
        # self.line2 = QLineEdit(self)
        self.line3 = QLineEdit(self)
        self.line4 = QLineEdit(self)
        self.lab1 = QLabel("课程",self)
        self.lab2 = QLabel("学期",self)
        # self.box1 = QCheckBox("班级",self)
        self.lab3 = QLabel("学院",self)
        self.btn1 = QPushButton("预览",self)
        self.btn2 = QPushButton("导出文档报告",self)
        self.btn3 = QPushButton("导出Excel",self)
        self.btn4 = QPushButton("导出提交报告",self)
        self.firstline.addWidget(self.lab1)
        self.firstline.addWidget(self.line1)
        # self.firstline.addWidget(self.box1)
        # self.firstline.addWidget(self.line2)
        self.firstline.addWidget(self.btn1)
        self.firstline.addWidget(self.btn2)
        self.secondline.addWidget(self.lab2)
        self.secondline.addWidget(self.line3)
        self.secondline.addWidget(self.lab3)
        self.secondline.addWidget(self.line4)
        self.secondline.addWidget(self.btn3)
        self.secondline.addWidget(self.btn4)
        self.outside.addLayout(self.firstline)
        self.outside.addLayout(self.secondline)

        self.layout = QHBoxLayout()
        self.layout.setSpacing(20)
        # 第一列按钮布局管理
        hLayout1 = QVBoxLayout()
        table = QTableWidget()
        table.setRowCount(4)
        table.setColumnCount(9)
        table.setMinimumSize(60, 50)
        table.setHorizontalHeaderLabels(
            ["毕业目标", "0-0.59", "0.60-0.69", "0.70-0.79", "0.80-0.89", "0.90-1.00", "平均值", "最低值", "最高值"])
        table.verticalHeader().setVisible(False)
        table.setItem(0, 0, QTableWidgetItem("目标1"))
        table.setItem(1, 0, QTableWidgetItem("目标2"))
        table.setItem(2, 0, QTableWidgetItem("目标3"))
        table.setItem(3, 0, QTableWidgetItem("目标4"))
        table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        table.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)
        table.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        hLayout1.addWidget(table)

        # 12张图
        inside = QGridLayout()
        for i in range(3):
            for j in range(4):
                lab = QLabel()
                self.png = QPixmap("excel_output/img/bar/分布柱状图.png")
                lab.setPixmap(self.png)
                lab.setMinimumSize(60, 30)
                lab.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                lab.setScaledContents(True)
                inside.addWidget(lab, i, j)
        hLayout1.addLayout(inside)
        hLayout1.setStretch(0, 1)
        hLayout1.setStretch(1, 1)
        # hLayout1.addStretch(2)
        # 第二行按钮布局管理
        hLayout2 = QVBoxLayout()
        lable = QTextEdit("请在这里输入点评")
        lable.setMinimumSize(80, 30)
        lable.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        hLayout2.addWidget(lable)
        lab = QLabel()
        self.png = QPixmap("excel_output/img/bar/分布柱状图.png")
        lab.setPixmap(self.png)
        lab.setScaledContents(True)

        lab.setMinimumSize(60, 30)
        lab.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        hLayout2.addWidget(lab)
        hLayout2.setStretch(0, 1)
        hLayout2.setStretch(1, 1)
        # 整体水平布局管理
        self.layout.addLayout(hLayout1)
        self.layout.addLayout(hLayout2)

        self.layout.setStretch(0, 2)
        self.layout.setStretch(1, 1)

        self.outside.addLayout(self.layout)
        self.setLayout(self.outside)

        # self.table = QTableWidget(self)
        # self.lab3 = QLabel(self)
        # self.lab4 = QLabel(self)
        # self.pic = QPixmap("static/pic.jpg")
        # self.pic = self.pic.scaled(271,88)
        # self.lab3.setPixmap(self.pic)
        # self.lab4.setPixmap(self.pic)
        self.init_ui()
        self.set_widget_style()
    def init_ui(self):
        pal = QPalette(self.palette())
        pal.setColor(QPalette.Background,QColor(242,242,242))
        self.setAutoFillBackground(True)
        self.setPalette(pal)
        self.lab1.move(15,15)
        self.lab2.move(15,50)
        self.line1.move(50,20)
        # self.line2.move(50,55)
        # self.box1.move(180,15)
        self.lab3.move(180,55)
        self.line3.move(235,20)
        self.line4.move(235,55)
        self.btn1.move(360,15)
        self.btn2.move(460,15)
        self.btn3.move(360,55)
        self.btn4.move(460,55)
        # self.table.move(15,90)
        # self.lab3.move(15,290)
        # self.lab4.move(320,290)
    def set_widget_style(self):
        font = QFont("PingFang SC Regular")
        font.setPixelSize(16)
        self.lab1.setFont(font)
        self.lab2.setFont(font)
        # self.box1.setFont(font)
        self.lab3.setFont(font)
        # self.table.setFixedSize(580,185)
if __name__=="__main__":
    app = QApplication(sys.argv)
    window = Test()
    window.show()
    sys.exit(app.exec_())